package com.example.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.entity.First;
import com.example.entity.Result;
import com.example.service.IFirstService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-11-11
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/first")
@Slf4j
@CrossOrigin
public class FirstController {

    private final IFirstService iFirstService;

    @DeleteMapping("/delete")
    public Result delete(@RequestParam List<Long> ids) throws Exception {
        iFirstService.removeByIds(ids);
        return Result.success();
    }

    @PostMapping("/save")
    public Result save(@RequestBody First first){
        log.info("增加一级标签：{}",first);
        iFirstService.save(first);
        return Result.success();
    }

    @GetMapping("/select")
    public Result<List<First>> sel(){
        log.info("获取一级标签");
        List<First> list = iFirstService.list(new LambdaQueryWrapper<First>()
                .eq(First::getJudge,0));
        return Result.success(list);
    }
}
